import { userRegister } from '@/api/user.js';
import { checkMobile ,checkEmail, checkUserName ,checkPassword } from '@/utils/validator.js'

export default {
	data() {
		return {
			formData: {
				phone: '18300000000',
				email: 'liqiwei123@outlook.com',
				loginName: 'shasha',
				userName: 'shasha',
				password: 'd23s3aaf',
				confirmPassword: 'd23s3aaf',
			},
		};
	},
	methods: {
		//注册
		async toRegister() {
			//校验数据
			if(!checkMobile(this.formData.phone) 
				|| !checkEmail(this.formData.email) 
				|| !checkUserName(this.formData.loginName) 
				|| !checkUserName(this.formData.userName) 
				|| !checkPassword(this.formData.password) 
				|| !checkPassword(this.formData.confirmPassword) ){
				return;
			}
			//密码和确认密码是否相等
			if(this.formData.password != this.formData.confirmPassword){
				uni.showToast({
					icon: 'error',
					title: '确认密码不正确',
					duration:2500
				});
				return;
			}
			//注册请求
			userRegister(this.formData).then(response => {
				uni.navigateTo({url:'/pages/user/login/login'});
			});
		},
	},
}